import fs from "node:fs";
import path from "node:path";

const dir = path.resolve(import.meta.dirname, "../static");
const staticFiles = fs.readdirSync(path.resolve(dir));
try {
    fs.rmdirSync(path.resolve(import.meta.dirname, "../src/static"), {
        recursive: true,
    });
} catch (err) {
    // ignore
}
fs.mkdirSync(path.resolve(import.meta.dirname, "../src/static"));

for (const file of staticFiles) {
    const filePath = path.resolve(dir, file);
    const destPath = path.resolve(
        import.meta.dirname,
        "..",
        "src",
        "static",
        `${file}.ts`
    );
    const content = fs.readFileSync(filePath);
    fs.writeFileSync(destPath, `// autogenerated\nexport default \`${content}\` as string;\n`);
}
